class Solution {
public:
    ListNode* reverseList(ListNode* head) {
        auto newhead=new ListNode(0);
        auto p=head;
        while(p){
            auto q=p->next;
            p->next=newhead->next;
            newhead->next=p;
            p=q;
        }
        return newhead->next;
        
    }
};